import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts

Dialog {
    id: filePickerDialog
    title: "文件选择"
    modal: true
    standardButtons: Dialog.Open | Dialog.Cancel

    property string selectedFilePath: ""
    property var fileDialog: null

    ColumnLayout {
        anchors.fill: parent
        spacing: 10

        Label {
            text: "选择的文件:"
            font.bold: true
        }

        TextField {
            id: filePathField
            Layout.fillWidth: true
            readOnly: true
            text: selectedFilePath
            placeholderText: "未选择文件"
        }

        Button {
            text: "浏览..."
            Layout.alignment: Qt.AlignRight
            onClicked: {
                if (!fileDialog) {
                    fileDialog = fileDialogComponent.createObject(filePickerDialog)
                }
                fileDialog.open()
            }
        }
    }

    Component {
        id: fileDialogComponent
        FileDialog {
            title: "请选择文件"
            nameFilters: ["所有文件 (*.*)"]
            onAccepted: {
                selectedFilePath = selectedFile
                filePathField.text = selectedFile
            }
        }
    }

    onAccepted: {
        if (selectedFilePath) {
            console.log("选择的文件:", selectedFilePath)
        }
    }
} 